import request from '@neu/biz-core/utils/request'
const baseUrl = 'dcam/api/w/fixed/inventory/dutys'
import { list as dList } from '@neu/dcam-ui/api/dictionary'

export const list = (params) => {
  return request({
    url: baseUrl,
    params,
    method: 'get'
  })
}

export const page = (params) => {
  return request({
    url: baseUrl + '/p',
    params,
    method: 'get'
  })
}

export const create = (data) => {
  return request({
    url: baseUrl,
    data,
    method: 'post'
  })
}

export const remove = (id) => {
  return request({
    url: baseUrl + '/' + id,
    method: 'delete'
  })
}

export const detail = (id) => {
  return request({
    url: baseUrl + '/' + id,
    method: 'get'
  })
}

export const enable = (id, status) => {
  return request({
    url: baseUrl + '/enable/' + id + '/status/' + status,
    method: 'put'
  })
}

export const update = (id, data) => {
  return request({
    url: baseUrl + '/' + id,
    data,
    method: 'put'
  })
}

export const status = () => {
  return dList({ s_type: 'inventoryDutyStatus' })
}

export const exportDetail = (id) => {
  return request({
    url: baseUrl + '/export/' + id,
    method: 'get',
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/octet-stream'
    }
  })
}

export const listMy = (params) => {
  return request({
    url: baseUrl + '/me',
    params,
    method: 'get'
  })
}

export const pageMy = (params) => {
  return request({
    url: baseUrl + '/me/p',
    params,
    method: 'get'
  })
}

export const importExcelUrl = (dutyId) => {
  return baseUrl + '/import/' + dutyId
}

// 下载离线盘点文件
export const downloadMyPan = () => {
  return request({
    url: baseUrl + '/download/me',
    method: 'get',
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/octet-stream'
    }
  })
}

// 上传离线盘点文件
export const uploadMyPanUrl = baseUrl + '/upload/me'

export const histories = (id) => {
  return request({
    url: baseUrl + '/' + id + '/histories',
    method: 'get'
  })
}

export const reject = (id, reason) => {
  return request({
    url: baseUrl + '/' + id + '/reject',
    data: {
      reason
    },
    method: 'put'
  })
}
